package com.wica.facetube;

import java.io.IOException;
import java.util.Vector;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Log;

import com.wica.model.MovieClip;

//public class FaceTubeService extends Service {
public class FaceTubeService {
	// *************** Constants ************** //
	// SOAP connection constants
	private static final String NAMESPACE = "http://webservice.facetube.wica.intec.ugent.be/";
	private static final String URL_WSDL = "http://wicaweb2.intec.ugent.be/FaceTubeWebServiceService/FaceTubeWebService";
	// Log constants
	private static final String LOG_TAG = "__FT.FaceTubeService__";
	// YouTube constants
	/* Order the list generated by a searchquery by relevance */
	private static final int ORDER_BY_RELEVANCE = 11;
	/* Order the list generated by a searchquery by viewcount */
	private static final int ORDER_BY_VIEWCOUNT = 12;
	/* Order the list generated by a searchquery by rating */
	private static final int ORDER_BY_RATING = 13;
	/* ----------------------- */

	/* -------- METHODS -------- */	
	public void getAllLocations(){
		// Constants
		final String METHOD_NAME = "getAllLocations";		
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 
        // Local variables
        int index;     

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"getAllLocations"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;       
        try {
        	// Call to webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);	    
	        // Get the SOAP Envelope back and then extract the body
	        soap = (SoapObject) envelope.bodyIn;
			// Get received data and build data objects in the loop
			index = soap.getPropertyCount();
			while (index-->0){
				/*
				 * 
				 * build object here
				 * 
				 * 
				 * 
				 */			
				Log.v(LOG_TAG,soap.getProperty(index).toString());
			}
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
		}
	}// getAllLocations method
	
	public void faceTubeGetAllEnvironments(){
		// Constants
		final String METHOD_NAME = "getAllEnvironments";		
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 
        // Local variables
        int index;     

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeGetAllEnvironments"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;        
        try {
    		// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);	    
	        // Get the SOAP Envelope back and the extract the body
	        soap = (SoapObject) envelope.bodyIn;
			// Get received data and build data objects in the loop
			index = soap.getPropertyCount();
			while (index-->0){
				/*
				 * 
				 * build object here
				 * 
				 * 
				 * 
				 */			
				Log.v(LOG_TAG,soap.getProperty(index).toString());
			}
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
		}      
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeGetAllEnvironments"+"("+")"+" -");
		Log.v(LOG_TAG, "----------------------------------------");
	}// faceTubeGetAllEnvironments method
	
	public void faceTubeGetAllMoods(){
		// Constants
		final String METHOD_NAME = "getAllMoods";		
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 
        // Local variables
        int index;     

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeGetAllMoods"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;        
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);	    
	        // Get the SOAP Envelope back and then extract the body
	        soap = (SoapObject) envelope.bodyIn;
			// Get received data and build data objects in the loop
			index = soap.getPropertyCount();
			while (index-->0){
				/*
				 * 
				 * build object here
				 * 
				 * 
				 * 
				 */			
				Log.v(LOG_TAG,soap.getProperty(index).toString());
			}
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
		}      
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeGetAllMoods"+"("+")"+" -");
		Log.v(LOG_TAG, "----------------------------------------");
	}// faceTubeGetAllMoods method
	
	
	/**
	 * Arguments: (regarding PersonalTV Fixed Version (previously named FaceTube Fixed Version)
	 * 		Long facebookID 
	 * Return
	 * 		OK:			userID (creates a new userID if needed)
	 * 
	 **/
	public Long faceTubeFacebookID2userID(Long facebookID){		
		// Constants
		final String METHOD_NAME = "facebookID2userID";
		final String ARGUMENT0 = "arg0";		
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeFacebookID2userID"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        
        transport.debug=true;
        
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, facebookID);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;    	
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Get the SOAP Envelope back and then extract the body        	
	        soap = (SoapObject) envelope.bodyIn;
			// Get data from WS and return it			
	        return(new Long(soap.getProperty("return").toString()));	        
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
			return (new Long(-1));
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
			return (new Long(-2));
		}
	}// faceTubeFacebookID2userID method
	
	public void faceTubeGetMovieclip(String movieClip){
		// Constants
		final String METHOD_NAME = "getMovieclip";
		final String ARGUMENT0 = "arg0";
		final int INDEX_FIRST_TAG = 14;		
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 
        // Local Variables
        int index;

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeGetMovieclip"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, movieClip);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Get the SOAP Envelope back and then extract the body
	        soap = (SoapObject) envelope.bodyIn;
	        // Build domain object from the SoapObject got
	        SoapObject so = (SoapObject) soap.getProperty("return");	        
	        SoapObject soc = (SoapObject)so.getProperty("categoryID");
//	        Log.v(LOG_TAG,soc.getProperty("description").toString());
//	        Log.v(LOG_TAG,soc.getProperty("id").toString());
//	        Log.v(LOG_TAG,soc.getProperty("term").toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("description")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("duration")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("format1")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("format5")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("format6")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("id")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("title")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("totalrating")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("URLThumbnail")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("url")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("viewcount")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("category")).toString());
//	        Log.v(LOG_TAG,((SoapPrimitive)so.getProperty("roundRating")).toString());
//	        /*varios tags*/
//	        for (index=INDEX_FIRST_TAG;(so.getPropertyCount()-index)>0;index++){
//	        	Log.v(LOG_TAG,so.getPropertyCount()-index+"        "+(SoapPrimitive)so.getProperty(index));
//	        }	        
			// Get data from WS and return it			
//	        return(new Long(soap.getProperty("return").toString()));	        
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
//			return (new Long(-1));
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
//			return (new Long(-2));
		}
	}// faceTubeGetMovieclip method	
	
	/**	Returns: 
	 * 		Vector<MovieClip> "numberOfResults" most viewed clips in "time"
	 * 	Parameters: (regarding FaceTube WebService)
	 * 		numberOfResults: Integer -- 0..30
	 * 		time: String 			-- All Time:   "all_time"  ""  null
	 * 								-- This Month: "this_month"
	 * 								-- This Week:  "this_week"
	 * 								-- Today:	   "today"
	 **/
	public Vector<MovieClip> getMostViewed(Integer numberOfResults, String time){
		if (time.compareTo("all_time")!=0 && time.compareTo("")!=0 && time!=null && time.compareTo("this_month")!=0 && time.compareTo("this_week")!=0 && time.compareTo("today")!=0){
			Log.e(LOG_TAG, "Not a valid \"time\" parameter when calling "+"FaceTubeService"+"->"+"getMostViewed"+"\nIt should be: \"all_time\",\"\",null,\"this_month\",\"this_week\",\"today\"");			System.exit(-1);
		}
		// Constants
		final String METHOD_NAME = "getMostViewed";
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap,mostviewed; 
        // Local Variables
        int index=0;
		Vector<MovieClip> ListOfMovies = new Vector<MovieClip>();

		Log.v(LOG_TAG,LOG_TAG+"--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG,LOG_TAG+"- "+"FaceTubeService"+"->"+"faceTubeGetMostViewed"+"("+"number of results "+numberOfResults+", "+"time "+time+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0 and ARGUMENT1
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, numberOfResults);
		soap.addProperty(ARGUMENT1, time);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;        
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Get the SOAP Envelope back and then extract the body
        	// we get mostviewed list from envelope
        	mostviewed = (SoapObject) envelope.bodyIn;
			Log.v(LOG_TAG,LOG_TAG+"Number of Videos "+mostviewed.getPropertyCount()+"");
	        // we walk mostviewed building a domain object in each iteration
        	for(index=0;index<mostviewed.getPropertyCount();index++){
    			soap = (SoapObject) mostviewed.getProperty(index);
    			if (soap.getProperty(0).toString().compareTo("anyType{}")!=0){
    				String tags = "";
    				for (int index_tag = INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag)>0;index_tag++){
    		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag+"        "+(SoapPrimitive)soap.getProperty(index_tag));
    		        	tags=tags+" "+(SoapPrimitive)soap.getProperty(index_tag);
    		        }

        				ListOfMovies.add(new MovieClip(	((SoapPrimitive)soap.getProperty("description")).toString(),
    													Integer.valueOf(((SoapPrimitive)soap.getProperty("duration")).toString()),
    													((SoapPrimitive)soap.getProperty("format1")).toString(),
    													((SoapPrimitive)soap.getProperty("format5")).toString(),
    													((SoapPrimitive)soap.getProperty("format6")).toString(),
    													((SoapPrimitive)soap.getProperty("title")).toString(),
    													Float.valueOf(((SoapPrimitive)soap.getProperty("totalrating")).toString()),
    													((SoapPrimitive)soap.getProperty("URLThumbnail")).toString(),
    													((SoapPrimitive)soap.getProperty("url")).toString(),
    													Integer.valueOf(((SoapPrimitive)soap.getProperty("viewcount")).toString()),
    													((SoapPrimitive)soap.getProperty("category")).toString(),
    													Float.valueOf(((SoapPrimitive)soap.getProperty("roundRating")).toString()),
    													tags));    			

    			}
        	}
	        return(ListOfMovies);	        
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG+"xmlparser",e.getMessage());
			return ListOfMovies;
		} catch (IOException e) {
			Log.e(LOG_TAG+"io",e.getMessage());
			Log.e(LOG_TAG, "indice: "+index);
			return ListOfMovies;
		}
	}// getMostViewed method		
	
	public void faceTubeGetLastViewed(Integer numberOfResults, Integer userID){
		/* Returns: 
		 * 		"numberOfResults" most viewed clips in "time"
		 * Parameters: (regarding FaceTube WebService)
		 * 		numberOfResults: Integer -- 0..60
		 * 		userID: Integer
		 */
		// Constants
		final String METHOD_NAME = "getLastViewed";
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final int MAX_NUMBEROFRESULTS = 60;
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap,soapCategory,lastviewed; 
        // Local Variables
        int index;

		if (numberOfResults<=0){
			Log.e(LOG_TAG, "Not a valid \"numberOfResults\" parameter when calling "+"FaceTubeService"+"->"+"faceTubeGetLastViewed"+"\nIt should bigger than 0");
			return;
		} else if (numberOfResults>MAX_NUMBEROFRESULTS){
			numberOfResults=MAX_NUMBEROFRESULTS;
			Log.v(LOG_TAG, "The \"numberOfResults\" asked is too high. It is restricted to "+MAX_NUMBEROFRESULTS);
		}
        
		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeGetLastViewed"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0 and ARGUMENT1
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, numberOfResults);
		soap.addProperty(ARGUMENT1, userID);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Get the SOAP Envelope back and then extract the body
        	// we get lastviewed list from envelope
        	lastviewed = (SoapObject) envelope.bodyIn;
	        // we walk personalized list building a domain object in each iteration
        	for(index=0;index<lastviewed.getPropertyCount();index++){
				soap = (SoapObject) lastviewed.getProperty(index);		        	        
		        soapCategory = (SoapObject)soap.getProperty("categoryID");
//		        Log.v(LOG_TAG,soapCategory.getProperty("description").toString());
//		        Log.v(LOG_TAG,soapCategory.getProperty("id").toString());
//		        Log.v(LOG_TAG,soapCategory.getProperty("term").toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("description")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("duration")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format1")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format5")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format6")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("id")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("title")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("totalrating")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("URLThumbnail")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("url")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("viewcount")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("category")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("roundRating")).toString());
//		        /*varios tags*/
//		        for (index_tag=INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag)>0;index_tag++){
//		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag+"        "+(SoapPrimitive)soap.getProperty(index_tag));
//		        }        		
        	}	        
	        
// Get data from WS and return it			
//	        return(new Long(soap.getProperty("return").toString()));	        
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
//			return (new Long(-1));
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
//			return (new Long(-2));
		}
	}// faceTubeGetMostViewed method	
	
	final int INDEX_FIRST_TAG = 14;

	public Vector<MovieClip> getPersonalizedClips(Integer numberOfResults, Integer userID){
		/* Returns: 
		 * 		personalized list for "userID" with "numberOfResults" clips
		 * Parameters: (regarding FaceTube WebService)
		 * 		numberOfResults: Integer -- Restricted to 1..60 (0..* in facetube Webservice) 
		 * 		userID: Integer			 
		 */
		// Constants
		final String METHOD_NAME = "getPersonalizedClips";
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final int MAX_NUMBEROFRESULTS = 60;
		Vector<MovieClip> ListOfMovies = new Vector<MovieClip>();

		if (numberOfResults<=0){
			Log.e(LOG_TAG, "Not a valid \"numberOfResults\" parameter when calling "+"FaceTubeService"+"->"+"getPersonalizedClips"+"\nIt should bigger than 0");
			return ListOfMovies;
		} else if (numberOfResults>MAX_NUMBEROFRESULTS){
			numberOfResults=MAX_NUMBEROFRESULTS;
			Log.v(LOG_TAG, "The \"numberOfResults\" asked is too high. It is restricted to "+MAX_NUMBEROFRESULTS);
		}
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap,soapCategory,personalizedListOfClips; 
        // Local Variables
        int index,index_tag;

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"getPersonalizedClips"+"(numberOfResults="+numberOfResults+",userID="+userID+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0 and ARGUMENT1
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, numberOfResults);
		soap.addProperty(ARGUMENT1, userID);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Get the SOAP Envelope back and then extract the body
        	// we get personalized list from envelope
        	personalizedListOfClips = (SoapObject) envelope.bodyIn;
	        // we walk personalized list building a domain object in each iteration
        	for(index=0;index<personalizedListOfClips.getPropertyCount();index++){
				soap = (SoapObject) personalizedListOfClips.getProperty(index);
    			if (soap.getProperty(0).toString().compareTo("anyType{}")!=0&&((SoapPrimitive)soap.getProperty("format6")).toString().compareTo("none")!=0){
    				String tags = "";
    				for (index_tag=INDEX_FIRST_TAG+1;(soap.getPropertyCount()-index_tag)>0;index_tag++){
    		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag+"        "+(SoapPrimitive)soap.getProperty(index_tag));
    		        	tags=tags+" "+(SoapPrimitive)soap.getProperty(index_tag);
    		        }
    				ListOfMovies.add(new MovieClip(	((SoapPrimitive)soap.getProperty("description")).toString(),    			
													Integer.valueOf(((SoapPrimitive)soap.getProperty("duration")).toString()),
													((SoapPrimitive)soap.getProperty("format1")).toString(),
													((SoapPrimitive)soap.getProperty("format5")).toString(),
													((SoapPrimitive)soap.getProperty("format6")).toString(),
													((SoapPrimitive)soap.getProperty("title")).toString(),
													Float.valueOf(((SoapPrimitive)soap.getProperty("totalrating")).toString()),
													((SoapPrimitive)soap.getProperty("URLThumbnail")).toString(),
													((SoapPrimitive)soap.getProperty("url")).toString(),
													Integer.valueOf(((SoapPrimitive)soap.getProperty("viewcount")).toString()),
													((SoapPrimitive)soap.getProperty("category")).toString(),
													Float.valueOf(((SoapPrimitive)soap.getProperty("roundRating")).toString()),
    												tags));
    			}
//		        soapCategory = (SoapObject)soap.getProperty("categoryID");
//		        Log.v(LOG_TAG,soapCategory.getProperty("description").toString());
//		        Log.v(LOG_TAG,soapCategory.getProperty("id").toString());
//		        Log.v(LOG_TAG,soapCategory.getProperty("term").toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("description")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("duration")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format1")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format5")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format6")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("id")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("title")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("totalrating")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("URLThumbnail")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("url")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("viewcount")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("category")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("roundRating")).toString());
		        /*varios tags*/
		                		
        	}	        
// Get data from WS and return it			
//	        return(new Long(soap.getProperty("return").toString()));
	        return(ListOfMovies);
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,"dober dan"+e.getMessage());
			return ListOfMovies;
		} catch (IOException e) {
			Log.e(LOG_TAG,"dober dan 2"+e.getMessage());
			return ListOfMovies;
		}
	}// getPersonalizedClips method	

	
	public Vector<MovieClip> getGeolocatedPersonalizedClips(String latLong,String radius,String category,Integer numberOfResults,Integer userID) {
		/* Returns: 
		 * 		personalized list of videos within a "radius" around a given location "latLong" 
		 * Parameters: (regarding FaceTube WebService)
		 * 		latLong: String "51.063704,3.721747" "Gent,Belgium"
		 * 		radius: String "1km"
		 * 		category: String
		 * 		numberOfResults: Integer -- Restricted to 1..60 (0..* in facetube Webservice) 
		 * 		userID: Integer			 
		 */
//		Log.v(LOG_TAG,"moviden en general");
		
		// Constants
		final String METHOD_NAME = "getGeolocatedPersonalizedClips";
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final String ARGUMENT2 = "arg2";
		final String ARGUMENT3 = "arg3";
		final String ARGUMENT4 = "arg4";

		final int INDEX_FIRST_TAG = 14;
		final int MAX_NUMBEROFRESULTS = 60;
		Vector<MovieClip> ListOfMovies = new Vector<MovieClip>();

		if (numberOfResults<=0){
			Log.e(LOG_TAG, "Not a valid \"numberOfResults\" parameter when calling "+"FaceTubeService"+"->"+"getPersonalizedClips"+"\nIt should bigger than 0");
			return ListOfMovies;
		} else if (numberOfResults>MAX_NUMBEROFRESULTS){
			numberOfResults=MAX_NUMBEROFRESULTS;
			Log.v(LOG_TAG, "The \"numberOfResults\" asked is too high. It is restricted to "+MAX_NUMBEROFRESULTS);
		}
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap,soapCategory,personalizedListOfClips;
        String latLong2="";
        String[] var = latLong.split(",");
        String latitude = var[0];
        int index2=0;
        double latitudeDouble = new Double(latitude);
        String longitude = var[1];
        double longitudeDouble = new Double(longitude);
        // Local Variables
        int index,index_tag;

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"getGeolocatedPersonalizedClips"+"(latLong="+latLong+",radius="+radius+",category="+category+",numberOfResults="+numberOfResults+",userID="+userID+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0 and ARGUMENT1
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, latLong);
		soap.addProperty(ARGUMENT1, radius);
		soap.addProperty(ARGUMENT2, category);
		soap.addProperty(ARGUMENT3, numberOfResults);
		soap.addProperty(ARGUMENT4, userID);

        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;       
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
            Log.v(LOG_TAG, LOG_TAG+"call done");

	        // Get the SOAP Envelope back and then extract the body
        	// we get personalized list from envelope
        	personalizedListOfClips = (SoapObject) envelope.bodyIn;
	        // we walk personalized list building a domain object in each iteration
        	for(index=0;index<personalizedListOfClips.getPropertyCount();index++){
        		soap = (SoapObject) personalizedListOfClips.getProperty(index);
//    			if (soap.getProperty(0).toString().compareTo("anyType{}")!=0)
//    				Log.v(LOG_TAG, "--------- DENTRO -------------"+latitudeDouble);
//	    			Log.v(LOG_TAG, "--------- "+((SoapPrimitive)soap.getProperty("format1")).toString()+" -------------");
//    			if ((SoapPrimitive)soap.getProperty("latLong")==null)
//	    			Log.v(LOG_TAG, "NULL "+(soap.getPropertyCount()+" -------------"));

//    				latLong2=((SoapPrimitive)soap.getProperty("latLong")).toString();
//    			else
	    			
	    			
	    		Double d1,d2,var2;
//	    		Log.v(LOG_TAG, soap.toString());
//	    		Log.v(LOG_TAG, ""+soap.toString().contains("latLong="));
//
//	    		
//	    		
//				if (soap.toString().contains("latLong=")){
//    				Log.v(LOG_TAG, "latLong Parameter INDEX="+index);
////	    			latLong2=((SoapPrimitive)soap.getProperty("latLong")).toString();
//    				latLong2="52,3";
//    				Log.v(LOG_TAG, "latLong Parameter "+latLong2+" INDEX="+index);
//				}else{
//    				Log.v(LOG_TAG, "MADE UP latLong Parameter "+""+" INDEX="+index);
//
//					var2 = new Double(Math.random()-Math.random());
//					if(var2>0)
//		    			d1 = latitudeDouble+(Math.random()/1E2);
//					else
//		    			d1 = latitudeDouble-(Math.random()/1E2);
//					var2 = new Double(Math.random()-Math.random());
//					if(var2>0)
//		    			d2 = longitudeDouble+(Math.random()/1E2);
//					else
//		    			d2 = longitudeDouble-(Math.random()/1E2);

//    				Log.v(LOG_TAG, var2+"___ENTERO___"+var2);
//
//					
//    				Log.v(LOG_TAG, d1+"");
//    				Log.v(LOG_TAG, d2+"");
//    				latLong2=d1+","+d2;
//    				soap.toString().contains("latLong=");
//    				Log.v(LOG_TAG, "movidas chungas "+soap);
//    				Log.v(LOG_TAG, "movidas chungas "+soap.getNamespace());
//    				Log.v(LOG_TAG, "movidas chungas "+soap.getPropertyInfo(index_tag, properties, propertyInfo));
//    				Log.v(LOG_TAG, "movidas chungas "+soap.getName());
//    				Log.v(LOG_TAG, "___________latLong2__________"+((SoapPrimitive)soap.getName().getProperty(5)).toString()+"_________");
				latLong2=((SoapPrimitive)soap.getProperty("latLong")).toString();
				if (latLong2.length()==1){					
					var2 = new Double(Math.random()-Math.random());
					if(var2>0)
		    			d1 = latitudeDouble+(Math.random()*1.5/1E2);
					else
		    			d1 = latitudeDouble-(Math.random()*1.5/1E2);
//					Log.v(LOG_TAG,"d1 NEG/POS"+var2+"");
					var2 = new Double(Math.random()-Math.random());
					if(var2>0)
		    			d2 = longitudeDouble+(Math.random()*1.5/1E2);
					else
		    			d2 = longitudeDouble-(Math.random()*1.5/1E2);
    				latLong2=d1+","+d2;
//					Log.v(LOG_TAG,"d2 NEG/POS"+var2+"");
				}
				//}
    			if (soap.getProperty(0).toString().compareTo("anyType{}")!=0){
    				String tags = "";
    				for (int index_tag1 = INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag1)>0;index_tag1++){
    		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag1+"        "+(SoapPrimitive)soap.getProperty(index_tag1));
    		        	tags=tags+" "+(SoapPrimitive)soap.getProperty(index_tag1);    		        	
    		        }
    				ListOfMovies.add(new MovieClip(		((SoapPrimitive)soap.getProperty("description")).toString(),
							Integer.valueOf(((SoapPrimitive)soap.getProperty("duration")).toString()),
							((SoapPrimitive)soap.getProperty("format1")).toString(),
							((SoapPrimitive)soap.getProperty("format5")).toString(),
							((SoapPrimitive)soap.getProperty("format6")).toString(),
							((SoapPrimitive)soap.getProperty("title")).toString(),
							Float.valueOf(((SoapPrimitive)soap.getProperty("totalrating")).toString()),
							((SoapPrimitive)soap.getProperty("URLThumbnail")).toString(),
							((SoapPrimitive)soap.getProperty("url")).toString(),
							Integer.valueOf(((SoapPrimitive)soap.getProperty("viewcount")).toString()),
							((SoapPrimitive)soap.getProperty("category")).toString(),
							Float.valueOf(((SoapPrimitive)soap.getProperty("roundRating")).toString()),
							latLong2,tags));
    			}


    				

//		        soapCategory = (SoapObject)soap.getProperty("categoryID");
//		        Log.v(LOG_TAG,soapCategory.getProperty("description").toString());
//		        Log.v(LOG_TAG,soapCategory.getProperty("id").toString());
//		        Log.v(LOG_TAG,soapCategory.getProperty("term").toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("description")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("duration")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format1")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format5")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format6")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("id")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("title")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("totalrating")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("URLThumbnail")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("url")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("viewcount")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("category")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("roundRating")).toString());
		        /*varios tags*/
//		        for (index_tag=INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag)>0;index_tag++){
//		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag+"        "+(SoapPrimitive)soap.getProperty(index_tag));
//		        }        		
        	}	        
// Get data from WS and return it			
//	        return(new Long(soap.getProperty("return").toString()));
        	if (ListOfMovies==null){
        		ListOfMovies=new Vector();
        	}
	        return(ListOfMovies);
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,"dober dan"+e.getMessage());
			return ListOfMovies;
		} catch (IOException e) {
			Log.e(LOG_TAG,"dober dan 2"+e.getMessage());
			return ListOfMovies;
		}
	}// getPersonalizedClips method	

	
	public Vector<MovieClip> getPersonalizedSearchClips(String searchString,Integer numberOfResults, Integer userID){
		/* Returns: 
		 * 		personalized list for "userID" with "numberOfResults" clips
		 * Parameters: (regarding FaceTube WebService)
		 * 		searchString: String
		 * 		numberOfResults: Integer -- Restricted to 1..60 (0..* in facetube Webservice) 
		 * 		userID: Integer			 
		 */
		// Constants
		final String METHOD_NAME = "getPersonalizedSearchClips";
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final String ARGUMENT2 = "arg2";
		final int INDEX_FIRST_TAG = 13;
		final int MAX_NUMBEROFRESULTS = 60;
		Vector<MovieClip> ListOfMovies = new Vector<MovieClip>();

		if (numberOfResults<=0){
			Log.e(LOG_TAG, "Not a valid \"numberOfResults\" parameter when calling "+"FaceTubeService"+"->"+"getPersonalizedSearchClips"+"\nIt should bigger than 0");
			return ListOfMovies;
		} else if (numberOfResults>MAX_NUMBEROFRESULTS){
			numberOfResults=MAX_NUMBEROFRESULTS;
			Log.v(LOG_TAG, "The \"numberOfResults\" asked is too high. It is restricted to "+MAX_NUMBEROFRESULTS);
		}
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap,personalizedListOfClips; 
        // Local Variables
        int index,index_tag;

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"getPersonalizedSearchClips(searchString="+searchString+", numberOfResults="+numberOfResults+", userID="+userID+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0 and ARGUMENT1
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, searchString);
		soap.addProperty(ARGUMENT1, numberOfResults);
		soap.addProperty(ARGUMENT2, userID);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Get the SOAP Envelope back and then extract the body
        	// we get personalized list from envelope
        	personalizedListOfClips = (SoapObject) envelope.bodyIn;
	        // we walk personalized list building a domain object in each iteration
        	Log.v(LOG_TAG,"NUMBER OF ACTUAL RESULTS: "+personalizedListOfClips.getPropertyCount()+"");
        	for(index=0;index<personalizedListOfClips.getPropertyCount();index++){
				soap = (SoapObject) personalizedListOfClips.getProperty(index);
    			if (soap.getProperty(0).toString().compareTo("anyType{}")!=0&&((SoapPrimitive)soap.getProperty("format6")).toString().compareTo("none")!=0){
    				String tags = "";
    				for (int index_tag1 = INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag1)>0;index_tag1++){
    		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag1+"        "+(SoapPrimitive)soap.getProperty(index_tag1));
    		        	tags=tags+" "+(SoapPrimitive)soap.getProperty(index_tag1);    		        	
    		        }

    				Log.v(LOG_TAG+"moviden",
        					"ListOfMovies.add(new MovieClip("
        					+((SoapPrimitive)soap.getProperty("description")).toString()+","
        					+Integer.valueOf(((SoapPrimitive)soap.getProperty("duration")).toString())+","
        					+((SoapPrimitive)soap.getProperty("format1")).toString()+","
        					+((SoapPrimitive)soap.getProperty("format5")).toString()+","
        					+((SoapPrimitive)soap.getProperty("format6")).toString()+","
        					+((SoapPrimitive)soap.getProperty("title")).toString()+","
        					+Float.valueOf(((SoapPrimitive)soap.getProperty("totalrating")).toString())+","
        					+((SoapPrimitive)soap.getProperty("URLThumbnail")).toString()+","
        					+((SoapPrimitive)soap.getProperty("url")).toString()+","
        					+Integer.valueOf(((SoapPrimitive)soap.getProperty("viewcount")).toString())+","
        					+((SoapPrimitive)soap.getProperty("category")).toString()+","
        					+Float.valueOf(((SoapPrimitive)soap.getProperty("roundRating")).toString())+","
        					+tags
        					+"");    				
    				
    				ListOfMovies.add(new MovieClip(		((SoapPrimitive)soap.getProperty("description")).toString(),
														Integer.valueOf(((SoapPrimitive)soap.getProperty("duration")).toString()),
							((SoapPrimitive)soap.getProperty("format1")).toString(),
							((SoapPrimitive)soap.getProperty("format5")).toString(),
							((SoapPrimitive)soap.getProperty("format6")).toString(),
							((SoapPrimitive)soap.getProperty("title")).toString(),
							Float.valueOf(((SoapPrimitive)soap.getProperty("totalrating")).toString()),
							((SoapPrimitive)soap.getProperty("URLThumbnail")).toString(),
							((SoapPrimitive)soap.getProperty("url")).toString(),
							Integer.valueOf(((SoapPrimitive)soap.getProperty("viewcount")).toString()),
							((SoapPrimitive)soap.getProperty("category")).toString(),
							Float.valueOf(((SoapPrimitive)soap.getProperty("roundRating")).toString()),tags));    						
    			}
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("description")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("duration")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format1")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format5")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format6")).toString());		        
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("title")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("totalrating")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("URLThumbnail")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("url")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("viewcount")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("category")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("published")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("roundRating")).toString());
		        /*varios tags*/
//		        for (index_tag=INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag)>0;index_tag++){
//		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag+"        "+(SoapPrimitive)soap.getProperty(index_tag));
//		        }     
        	}	        
// Get data from WS and return it			
//	        return(new Long(soap.getProperty("return").toString()));
	        return(ListOfMovies);
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
			return ListOfMovies;
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
			return ListOfMovies;
		}
	}// getPersonalizedSearchClips method	

	public void faceTubeGetRelatedClips(String videoURLID,Integer numberOfResults){
		/* Returns: 
		 * 		list of "numberOfResults" clips related to the video "videoURLID" 
		 * Parameters: (regarding FaceTube WebService)
		 * 		videoURLID: String 	-- YouTube Video ID instead of full URL 
		 * 							-- "dMH0bHeiRNg" instead of "http://www.youtube.com/v/dMH0bHeiRNg"
		 * 		numberOfResults: Integer -- Restricted to 1..60 (0..* in facetube Webservice) 
		 */
		// Constants
		final String METHOD_NAME = "getRelatedClips";
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final int INDEX_FIRST_TAG = 13;
		final int MAX_NUMBEROFRESULTS = 60;

		if (numberOfResults<=0){
			Log.e(LOG_TAG, "Not a valid \"numberOfResults\" parameter when calling "+"FaceTubeService"+"->"+"faceTubeGetPersonalizedSearchClips"+"\nIt should bigger than 0");
			return;
		} else if (numberOfResults>MAX_NUMBEROFRESULTS){
			numberOfResults=MAX_NUMBEROFRESULTS;
			Log.v(LOG_TAG, "The \"numberOfResults\" asked is too high. It is restricted to "+MAX_NUMBEROFRESULTS);
		}
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap,relatedListOfClips; 
        // Local Variables
        int index,index_tag;

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeGetRelatedClips"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0 and ARGUMENT1
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, videoURLID);
		soap.addProperty(ARGUMENT1, numberOfResults);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Get the SOAP Envelope back and then extract the body
        	// we get relatedClips list from envelope
        	relatedListOfClips = (SoapObject) envelope.bodyIn;
	        // we walk relatedClips list building a domain object in each iteration
        	for(index=0;index<relatedListOfClips.getPropertyCount();index++){
				soap = (SoapObject) relatedListOfClips.getProperty(index);		        	        
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("description")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("duration")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format1")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format5")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format6")).toString());		        
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("title")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("totalrating")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("URLThumbnail")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("url")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("viewcount")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("category")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("published")).toString());
		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("roundRating")).toString());
		        /*varios tags*/
		        for (index_tag=INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag)>0;index_tag++){
		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag+"        "+(SoapPrimitive)soap.getProperty(index_tag));
		        }        		
        	}	        
// Get data from WS and return it			
//	        return(new Long(soap.getProperty("return").toString()));	        
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
//			return (new Long(-1));
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
//			return (new Long(-2));
		}
	}// faceTubeGetRelatedClips method	

	
	public Vector<MovieClip> getTopRated(Integer numberOfResults, String time){
		/* Returns: 
		 * 		"numberOfResults" top rated clips in "time"
		 * Parameters: (regarding FaceTube WebService)
		 * 		numberOfResults: Integer -- 0..30
		 * 		time: String 			-- All Time:   "all_time"  ""  null
		 * 								-- This Month: "this_month"
		 * 								-- This Week:  "this_week"
		 * 								-- Today:	   "today"
		 */
		if (time.compareTo("all_time")!=0 && time.compareTo("")!=0 && time!=null && time.compareTo("this_month")!=0 && time.compareTo("this_week")!=0 && time.compareTo("today")!=0){
			Log.e(LOG_TAG, "Not a valid \"time\" parameter when calling "+"FaceTubeService"+"->"+"getTopRated"+"\nIt should be: \"all_time\",\"\",null,\"this_month\",\"this_week\",\"today\"");			System.exit(-1);
			System.exit(-1);
		}
		// Constants
		final String METHOD_NAME = "getTopRated";
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final int INDEX_FIRST_TAG = 12;		
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap,toprated; 
        // Local Variables
        int index,index_tag;
		Vector<MovieClip> ListOfMovies = new Vector<MovieClip>();

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"getTopRated"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0 and ARGUMENT1
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, numberOfResults);
		soap.addProperty(ARGUMENT1, time);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Get the SOAP Envelope back and then extract the body
        	// we get toprated list from envelope
        	toprated = (SoapObject) envelope.bodyIn;
	        // we walk toprated building a domain object in each iteration
    		Log.v(LOG_TAG,"number of results "+numberOfResults);
    		Log.v(LOG_TAG,"time "+time);
    		Log.v(LOG_TAG,"respuestas "+toprated.getPropertyCount());

        	for(index=0;index<toprated.getPropertyCount();index++){
				soap = (SoapObject) toprated.getProperty(index);
    			if (soap.getProperty(0).toString().compareTo("anyType{}")!=0){
    				String tags = "";
    				for (int index_tag1 = INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag1)>0;index_tag1++){
    		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag1+"        "+(SoapPrimitive)soap.getProperty(index_tag1));
    		        	tags=tags+" "+(SoapPrimitive)soap.getProperty(index_tag1);    		        	
    		        }
            		ListOfMovies.add(new MovieClip(		((SoapPrimitive)soap.getProperty("description")).toString(),
							Integer.valueOf(((SoapPrimitive)soap.getProperty("duration")).toString()),
							((SoapPrimitive)soap.getProperty("format1")).toString(),
							((SoapPrimitive)soap.getProperty("format5")).toString(),
							((SoapPrimitive)soap.getProperty("format6")).toString(),
							((SoapPrimitive)soap.getProperty("title")).toString(),
							Float.valueOf(((SoapPrimitive)soap.getProperty("totalrating")).toString()),
							((SoapPrimitive)soap.getProperty("URLThumbnail")).toString(),
							((SoapPrimitive)soap.getProperty("url")).toString(),
							Integer.valueOf(((SoapPrimitive)soap.getProperty("viewcount")).toString()),
							((SoapPrimitive)soap.getProperty("category")).toString(),
							Float.valueOf(((SoapPrimitive)soap.getProperty("roundRating")).toString()),
							tags));    				
    			}

//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("description")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("duration")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format1")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format5")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format6")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("title")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("totalrating")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("URLThumbnail")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("url")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("viewcount")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("category")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("roundRating")).toString());
		        /*varios tags*/
//		        for (index_tag=INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag)>0;index_tag++){
//		        	Log.v(LOG_TAG,soap.getPropertyCount()-index_tag+"        "+(SoapPrimitive)soap.getProperty(index_tag));
//		        }
        	}
	        return ListOfMovies;
// Get data from WS and return it			
//	        return(new Long(soap.getProperty("return").toString()));	        
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
			return ListOfMovies;
//			return (new Long(-1));
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
//			return (new Long(-2));
			return ListOfMovies;
		}
	}// getTopRated method	
	
	public void faceTubeRemoveMovieclip(String movieclipID){
		// Constants
		final String METHOD_NAME = "removeMovieclip";	
		final String ARGUMENT0 = "arg0";
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeRemoveMovieclip"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, movieclipID);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;        
        try {
        	// Call to webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);	    
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
		}		
	}// faceTubeRemoveMovieclip method

	
	public void faceTubeSaveRecommendationFromFriend(Integer userIDFrom, Integer userIDTo, String url ){
		/* Parameters: (regarding FaceTube WebService)
		 * 		userIDFrom: Integer -- userID of the users that recommend content
		 * 		userIDTo: 	Integer -- userID of the users to who content is being recommended
		 * 		url: 		String 	-- full URL e.g. "http://www.youtube.com/v/dMH0bHeiRNg"
		 */

		// Constants
		final String METHOD_NAME = "saveRecommendationFromFriend";	
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final String ARGUMENT2 = "arg2";
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeSaveRecommendationFromFriend"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, userIDFrom);
		soap.addProperty(ARGUMENT1, userIDTo);
		soap.addProperty(ARGUMENT2, url);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;        
        try {
        	// Call to webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);	    
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
		}		
	}// faceTubeSaveRecommendationFromFriend method
	
	public void faceTubeAddWatchedItem(Long facebookID, Integer percentageWatched, Integer userScore, String location, String mood, String environment, String URL){
		/* Parameters: (regarding FaceTube WebService)
		 * 		sessionID: Integer			--
		 * 		percentageWatched: short	--
		 * 		userScore: short			--
		 * 		location: String 			--
		 * 		mood: String				--
		 * 		environment: String			--
		 * 		URL: String 				-- 		
		 */

		// Constants
		final String METHOD_NAME = "addWatchedItemAdrian";	
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final String ARGUMENT2 = "arg2";
		final String ARGUMENT3 = "arg3";
		final String ARGUMENT4 = "arg4";
		final String ARGUMENT5 = "arg5";
		final String ARGUMENT6 = "arg6";
		
		// Local Variables
		// We need the userID from Facetube (by using facebook id)
//    	Long faceTubeUserID = 	this.faceTubeFacebookID2userID(facebookID);
    	// We need sessionID as well
    	Integer sessionID = 	this.faceTubeStartSession(Integer.valueOf(facebookID.toString()));
    	
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 
        
		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeAddWatchedItem"+"("+")"+" -");
		Log.v(LOG_TAG, "ARGUMENTS");
		Log.v(LOG_TAG, 	""+facebookID);
		Log.v(LOG_TAG, 	""+percentageWatched);
		Log.v(LOG_TAG, 	""+userScore);
		Log.v(LOG_TAG, 	location);
		Log.v(LOG_TAG, 	mood);
		Log.v(LOG_TAG, 	environment);
		Log.v(LOG_TAG, 	URL);
		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        transport.debug=true;
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, sessionID);
		soap.addProperty(ARGUMENT1, percentageWatched);
		soap.addProperty(ARGUMENT2, userScore);
		soap.addProperty(ARGUMENT3, location);
		soap.addProperty(ARGUMENT4, mood);
		soap.addProperty(ARGUMENT5, environment);
		soap.addProperty(ARGUMENT6, URL);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;        
        try {
        	// Call to webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
        	Log.v(LOG_TAG,"redios "+transport.requestDump);
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
		} 	
	}// faceTubeAddWatchedItem method	
	
	public void faceTubeAddWatchedItemAdrian(Long facebookID, Integer percentageWatched, Integer userScore, String location, String mood, String environment, String URL, String latLong){
		/* Parameters: (regarding FaceTube WebService)
		 * 		sessionID: Integer			--
		 * 		percentageWatched: short	--
		 * 		userScore: short			--
		 * 		location: String 			--
		 * 		mood: String				--
		 * 		environment: String			--
		 * 		URL: String 				--
		 * 		location: String 			--  		
		 */

		// Constants
		final String METHOD_NAME = "addWatchedItemAdrian";	
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final String ARGUMENT2 = "arg2";
		final String ARGUMENT3 = "arg3";
		final String ARGUMENT4 = "arg4";
		final String ARGUMENT5 = "arg5";
		final String ARGUMENT6 = "arg6";
		final String ARGUMENT7 = "arg7";

		// Local Variables
		// We need the userID from Facetube (by using facebook id)
//    	Long faceTubeUserID = 	this.faceTubeFacebookID2userID(facebookID);
    	// We need sessionID as well
    	Integer sessionID = this.faceTubeStartSession(Integer.valueOf(facebookID.toString()));
    	
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 
        
		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeAddWatchedItem"+"("+")"+" -");
		Log.v(LOG_TAG, "ARGUMENTS");
		Log.v(LOG_TAG, 	""+facebookID);
		Log.v(LOG_TAG, 	""+percentageWatched);
		Log.v(LOG_TAG, 	""+userScore);
		Log.v(LOG_TAG, 	location);
		Log.v(LOG_TAG, 	mood);
		Log.v(LOG_TAG, 	environment);
		Log.v(LOG_TAG, 	URL);
		Log.v(LOG_TAG, 	latLong);
		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        transport.debug=true;
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, sessionID);
		soap.addProperty(ARGUMENT1, percentageWatched);
		soap.addProperty(ARGUMENT2, userScore);
		soap.addProperty(ARGUMENT3, location);
		soap.addProperty(ARGUMENT4, mood);
		soap.addProperty(ARGUMENT5, environment);
		soap.addProperty(ARGUMENT6, URL);
		soap.addProperty(ARGUMENT7, latLong);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;        
        try {
        	// Call to webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
//        	Log.v(LOG_TAG,"redios "+transport.requestDump);
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
		}
	}// faceTubeAddWatchedItemAdrian method	


	
	public Integer faceTubeStartSession(Integer userID){
		// Constants
		final String METHOD_NAME = "startSession";	
		final String ARGUMENT0 = "arg0";
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeStartSession"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, userID);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;        
        try {
        	// Call to webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
        	return(Integer.valueOf(((SoapObject)envelope.bodyIn).getProperty("return").toString()));
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,"XmlPullParserException: "+e.getMessage());
			return(Integer.valueOf(-1));
		} catch (IOException e) {
			Log.e(LOG_TAG,"IOException: "+e.getMessage());
			return(Integer.valueOf(-2));
		}		
	}// faceTubeStartSession method
	
	public Integer faceTubeGetNumberOfDistinctItemsWatchedByUser(Integer userID){
		// Constants
		final String METHOD_NAME = "getNumberOfDistinctItemsWatchedByUser";	
		final String ARGUMENT0 = "arg0";
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap; 

		Log.v(LOG_TAG, "--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG, "- "+"FaceTubeService"+"->"+"faceTubeGetNumberOfDistinctItemsWatchedByUser"+"("+")"+" -");

		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, userID);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;        
        try {
        	// Call to webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Extract data from envelope   	
        	return Integer.valueOf(((SoapObject)envelope.bodyIn).getProperty(0).toString());
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
			return (-1);
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
			return (-2);
		}		
	}// faceTubeGetNumberOfDistinctItemsWatchedByUser method
	
	/** Returns: 
	 * 		personalized list for "userID" with "numberOfResults" clips
	 * 	Parameters: (regarding FaceTube WebService) 		 
	 * 		searchString: String
	 * 		numberOfResults: Integer 	-- Restricted to 1..30 (0..* in facetube Webservice)
	 * 		orderBy: int				-- by relevance "ORDER_BY_RELEVANCE = 11"
	 * 									-- by viewcount "ORDER_BY_VIEWCOUNT = 12"
	 * 									-- by rating 	"ORDER_BY_RATING	= 13"
	 * 		userID: Integer
	 **/
	public Vector<MovieClip> getRandomSearchClips(String searchString, Integer numberOfResults, int orderBy, Integer userID){
     	// Constants
		final String METHOD_NAME = "getRandomSearchClips";
		final String ARGUMENT0 = "arg0";
		final String ARGUMENT1 = "arg1";
		final String ARGUMENT2 = "arg2";
		final String ARGUMENT3 = "arg3";
		final int MAX_NUMBEROFRESULTS = 30;
		Vector<MovieClip> ListOfMovies = new Vector<MovieClip>();

		// Preconditions		
		if (numberOfResults<=0){
			Log.e(LOG_TAG, "Not a valid \"numberOfResults\" parameter when calling "+"FaceTubeService"+"->"+"faceTubeGetPersonalizedClips"+"\nIt should bigger than 0");
			if (orderBy!=ORDER_BY_RATING && orderBy!=ORDER_BY_RELEVANCE && orderBy!=ORDER_BY_VIEWCOUNT){
				Log.e(LOG_TAG, "Not a valid \"orderBy\" parameter when calling "+"FaceTubeService"+"->"+"faceTubeGetPersonalizedClips"+"\nIt should be:\n"+ORDER_BY_RATING+" order by rating\n"+ORDER_BY_RELEVANCE+" order by relevance\n"+ORDER_BY_VIEWCOUNT+" order by viewcount\n");			
			}
			return ListOfMovies;			
		} else if (numberOfResults>MAX_NUMBEROFRESULTS){
			numberOfResults=MAX_NUMBEROFRESULTS;
			Log.v(LOG_TAG, "The \"numberOfResults\" asked is too high. It is restricted to "+MAX_NUMBEROFRESULTS);
		}
		if (orderBy!=ORDER_BY_RATING && orderBy!=ORDER_BY_RELEVANCE && orderBy!=ORDER_BY_VIEWCOUNT){
			Log.e(LOG_TAG, "Not a valid \"orderBy\" parameter when calling "+"FaceTubeService"+"->"+"faceTubeGetPersonalizedClips"+"\nIt should be:\n"+ORDER_BY_RATING+" order by rating\n"+ORDER_BY_RELEVANCE+" order by relevance\n"+ORDER_BY_VIEWCOUNT+" order by viewcount\n");
			return ListOfMovies;
		}
		// SOAP Variables
		SoapSerializationEnvelope envelope;
        HttpTransportSE transport;
        SoapObject soap,randomSearchClips; 
        // Local Variables
        int index;

		Log.v(LOG_TAG,LOG_TAG+"--------- EXECUTING METHOD -------------");
		Log.v(LOG_TAG,LOG_TAG+"- "+"FaceTubeService"+"->"+"faceTubeGetRandomSearchClips"+"("+"String searchString = "+searchString+", Integer numberOfResults = "+numberOfResults+", int orderBy = "+orderBy+", Integer userID = "+userID+")"+" -");		
		// Initialize transport layer, envelope and soap objects
        transport = new HttpTransportSE(URL_WSDL);
        // build soap object we send to call the method METHOD_NAME with arguments ARGUMENT0 and ARGUMENT1
		soap = new SoapObject(NAMESPACE, METHOD_NAME);
		soap.addProperty(ARGUMENT0, searchString);
		soap.addProperty(ARGUMENT1, numberOfResults);
		soap.addProperty(ARGUMENT2, orderBy);
		soap.addProperty(ARGUMENT3, userID);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soap;
        try {
        	// Call webservice method
        	transport.call("http://schemas.xmlsoap.org/soap/envelope/", envelope);
	        // Get the SOAP Envelope back and then extract the body
        	// we get randomsearch list from envelope
        	randomSearchClips = (SoapObject) envelope.bodyIn;
	        // we walk randomsearch list building a domain object in each iteration
			Log.v(LOG_TAG,LOG_TAG+"Number of Videos "+randomSearchClips.getPropertyCount()+"");
        	for(index=0;index<randomSearchClips.getPropertyCount();index++){
				soap = (SoapObject) randomSearchClips.getProperty(index);
		        Log.v(LOG_TAG,index+" randomSearchClips.getPropertyCount() "+randomSearchClips.getPropertyCount());
		        if (soap.getProperty(0).toString().compareTo("anyType{}")!=0){
    				String tags = "";
//    				for (int index_tag1 = INDEX_FIRST_TAG;(soap.getPropertyCount()-index_tag1)>1;index_tag1++){
//    		        	Log.v(LOG_TAG+"moviden",soap.getPropertyCount()-index_tag1+"        "+(SoapPrimitive)soap.getProperty(index_tag1));
//    		        	tags=tags+" "+(SoapPrimitive)soap.getProperty(index_tag1);    		        	
//    		        }
    				Log.v(LOG_TAG+"moviden",tags+"");
    				
    				Log.v(LOG_TAG+"moviden",
    					"ListOfMovies.add(new MovieClip("
    					+((SoapPrimitive)soap.getProperty("description")).toString()+","
    					+Integer.valueOf(((SoapPrimitive)soap.getProperty("duration")).toString())+","
    					+((SoapPrimitive)soap.getProperty("format1")).toString()+","
    					+((SoapPrimitive)soap.getProperty("format5")).toString()+","
    					+((SoapPrimitive)soap.getProperty("format6")).toString()+","
    					+((SoapPrimitive)soap.getProperty("title")).toString()+","
    					+Float.valueOf(((SoapPrimitive)soap.getProperty("totalrating")).toString())+","
    					+((SoapPrimitive)soap.getProperty("URLThumbnail")).toString()+","
    					+((SoapPrimitive)soap.getProperty("url")).toString()+","
    					+Integer.valueOf(((SoapPrimitive)soap.getProperty("viewcount")).toString())+","
    					+((SoapPrimitive)soap.getProperty("category")).toString()+","
    					+Float.valueOf(((SoapPrimitive)soap.getProperty("roundRating")).toString())+","
    					+tags
    					+"");
    				
            		ListOfMovies.add(new MovieClip(		((SoapPrimitive)soap.getProperty("description")).toString(),
							Integer.valueOf(((SoapPrimitive)soap.getProperty("duration")).toString()),
							((SoapPrimitive)soap.getProperty("format1")).toString(),
							((SoapPrimitive)soap.getProperty("format5")).toString(),
							((SoapPrimitive)soap.getProperty("format6")).toString(),
							((SoapPrimitive)soap.getProperty("title")).toString(),
							Float.valueOf(((SoapPrimitive)soap.getProperty("totalrating")).toString()),
							((SoapPrimitive)soap.getProperty("URLThumbnail")).toString(),
							((SoapPrimitive)soap.getProperty("url")).toString(),
							Integer.valueOf(((SoapPrimitive)soap.getProperty("viewcount")).toString()),
							((SoapPrimitive)soap.getProperty("category")).toString(),
							Float.valueOf(((SoapPrimitive)soap.getProperty("roundRating")).toString()),tags));

		        }
        		/*
				soap = (SoapObject) randomSearchClips.getProperty(index);
		        soapCategory = (SoapObject)soap.getProperty("categoryID");
		        Log.v(LOG_TAG,soapCategory.getProperty("description").toString());
		        Log.v(LOG_TAG,soapCategory.getProperty("id").toString());
		        Log.v(LOG_TAG,soapCategory.getProperty("term").toString());
		        */
        		
        		
        		
        		
        		
        		
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("description")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("duration")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format1")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format5")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("format6")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("id")).toString());
//		        // We get all the "tagIDCollection"'s
//				for (index_tag=INDEX_FIRST_TAGIDCOLLECTION;!(soap.getProperty(index_tag).equals(soap.getProperty("title")));index_tag++){
//		        	tagIDCollection = (SoapObject)soap.getProperty(index_tag);
//		        	Log.v(LOG_TAG,"tagIDCollection-Description "+tagIDCollection.getProperty("description"));
//		        	Log.v(LOG_TAG,"tagIDCollection-ID "+tagIDCollection.getProperty("id"));
//		        	tagsourceID = (SoapObject)tagIDCollection.getProperty("tagsourceID");
//		        	Log.v(LOG_TAG,"tagIDCollection-tagsourceID-Description "+tagsourceID.getProperty("description"));
//		        	Log.v(LOG_TAG,"tagIDCollection-tagsourceID-ID "+tagsourceID.getProperty("id"));
//		        }
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("title")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("totalrating")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("URLThumbnail")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("url")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("viewcount")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("category")).toString());
//		        Log.v(LOG_TAG,((SoapPrimitive)soap.getProperty("roundRating")).toString());
//		        /*varios tags pero los tenemos en tagIDCollection-Description*/
//				/*------------------------------------------------------*/
        	}	        
// Get data from WS and return it	
        	Log.v(LOG_TAG,"NUMBER OF ACTUAL RESULTS.");
	        return ListOfMovies;
		} catch (XmlPullParserException e) {
			Log.e(LOG_TAG,e.getMessage());
			return (null);
		} catch (IOException e) {
			Log.e(LOG_TAG,e.getMessage());
			return (null);
		}
	}// faceTubeGetRandomSearchClips method

//	static private FaceTubeService singleton = null;
//	 
//    public FaceTubeService() { }
//
//    static public FaceTubeService getSingleton() {
//        if (singleton == null) {
//            singleton = new FaceTubeService();
//        }
//        return singleton;
//    }
	
}// FaceTubeService Class